<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    * {
      margin: 0;
      padding: 0;
    }
    .countdate{
        margin: 0 auto;
      width: 12.5rem;
      padding: 1.5rem;
      background: #f5222d;
      text-align: center;
      color: white;
    }
    span{
          width: 2.5rem;
          height: 2.5rem;
          background: #333;
          line-height: 2.5rem;
          margin: 0 .5rem;
          border-radius: .25rem;
        }
    </style>
</head>
<body>
    <div class="countdate">
        <p>今天是2222年2月22日</p>
        <h2>下班倒计时</h2>
        <p>
            <span class="hour">23</span>
            <span class="minute">30</span>
            <span class="second">31</span>
        </p>
        <p>18:30:00下课</p>
    </div>
    <script>
        const hour = document.querySelector('.hour')
        const minute = document.querySelector('.minute')
        const second = document.querySelector('.second')
    function fn(){
        const now = +new Date()
        const last = +new Date('2025-11-11 17:30:00')
        const count = (last - now)/1000
        // let d = parseInt(count / 60 /60 )
         h = parseInt(count / 60 /60 % 24)
         m = parseInt(count / 60 %60 )
         s = parseInt(count %60)
        h = h<10 ?'0'+ h:h 
        m = m <10 ?'0'+ m:m
        s = s <10 ?'0'+ s:s
        // console.log(d,h,m,s);
       hour.innerHTML = h 
       minute.innerHTML = m 
        second.innerHTML = s
        }
        fn()
        setInterval(fn,1000)
    </script>
</body>
</html>